<!doctype html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>练习6</title>
    <base href="/">
    <style>
        div {float:left; margin-right:10px;}
    </style>
    <script src="js/echarts.min.js"></script>
    <script src="js/jquery-3.3.1.min.js"></script>
</head>
<body>
<div id="scatter" style="width: 100%;height:600px;"></div>
<div><button>最高武力和最长寿命</button></div>
<script type="text/javascript">
        var option = {
            title: {
                text: '显示武将的生年，武力，寿命，姓名'
            },
            xAxis: {
                type: 'time',
                name: '出生年份'
            },
            yAxis: {
                scale: true,
                name: '武力'
            },
            dataZoom: [
                {
                    type: 'slider',
                    show: true,
                    xAxisIndex: [0],
                    start: 0,
                    end: 50
                },
                {
                    type: 'slider',
                    show: true,
                    yAxisIndex: [0],
                    start: 50,
                    end: 100
                },
                {
                    type: 'inside',
                    xAxisIndex: [0],
                    start: 0,
                    end: 50
                },
                {
                    type: 'inside',
                    yAxisIndex: [0],
                    start: 50,
                    end: 100
                }
            ],
            visualMap: {
                min: 0,
                max: 100,
                dimension: 1,
                orient: 'vertical',
                right: 10,
                top: 'center',
                text: ['HIGH', 'LOW'],
                calculable: true,
                inRange: {
                    color: ['#f2c31a', '#ff1112']
                }
            },
            series: [{
                type: 'scatter',
                symbolSize: function (data) {
                    return data[2]/5;
                },
                label: {
                    emphasis: {
                        show: true,
                        formatter: "{@[3]}（寿命{@[2]}）",
                        position: 'top',
                        color: '#000'
                    }
                }
            },{
                type: 'effectScatter',
                symbolSize: 20,
                label: {
                    emphasis: {
                        show: true,
                        formatter: "{@[3]}（寿命{@[2]}）",
                        position: 'top',
                        color: '#000'
                    }
                }
            }]
        };
        var scatterChart = echarts.init(document.getElementById('scatter'));
        $.get("stat/scatter/timeForceAndAge").done(function(data){
            option.series[0].data = data;
            draw(option);
        });

        $("button").click(function(){
            $.get("stat/scatter/maxForceOrAge").done(function(data){
                var old = scatterChart.getOption();
                option.dataZoom[0].start=old.dataZoom[0].start;
                option.dataZoom[0].end=old.dataZoom[0].end;
                option.dataZoom[1].start=old.dataZoom[1].start;
                option.dataZoom[1].end=old.dataZoom[1].end;
                option.dataZoom[2].start=old.dataZoom[2].start;
                option.dataZoom[2].end=old.dataZoom[2].end;
                option.dataZoom[3].start=old.dataZoom[3].start;
                option.dataZoom[3].end=old.dataZoom[3].end;
                option.series[1].data = data;
                draw(option);
            });
        });

        function draw(option) {
            scatterChart.setOption(option);
        }


</script>
</body>
</html>